package com.atguigu.serein.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisConfig {

    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        /**
         * 设置请求的页面大雨最大页后操作，true掉回到首页，false继续请求，默认false
         * paginationINterceptor.setOverflow(false)
         * 设置最大但也限制数量，默认500条, -1 不受限制
         * paginationInterceptor.setlimit(500)
         * 开启 count 的 join优化，只针对left joints
         */


        //这是分页拦截器
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        //是否溢出，超过页数跳回首页
        paginationInnerInterceptor.setOverflow(true);
        //设置单页最大记录
        paginationInnerInterceptor.setMaxLimit(500L);

        mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);

        return mybatisPlusInterceptor;
    }
}
